package com.zsc.oj.zojcodesendbox.controller;

import com.zsc.oj.zojcodesendbox.judge.ExecuteCodeRequest;
import com.zsc.oj.zojcodesendbox.judge.ExecuteCodeResponse;
import com.zsc.oj.zojcodesendbox.judge.JavaDockerCodeSendBox;
import com.zsc.oj.zojcodesendbox.judge.JavaNativeCodeSendBox;
import com.zsc.oj.zojcodesendbox.judge.c.CNativeCodeSendBox;
import com.zsc.oj.zojcodesendbox.judge.python.PythonNativeCodeSendBox;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/")
public class execCodeSendBoxController {

    @Resource
    private JavaDockerCodeSendBox javaDockerCodeSendBox;

    @Resource
    private JavaNativeCodeSendBox javaNativeCodeSendBox;

    @Resource
    private PythonNativeCodeSendBox pythonNativeCodeSendBox;

    @Resource
    private CNativeCodeSendBox  cNativeCodeSendBox;

    @PostMapping("executeCode")
    public ExecuteCodeResponse executeCode(@RequestBody ExecuteCodeRequest executeCodeRequest){
        if(executeCodeRequest == null){
            throw new RuntimeException("请求参数为空");
        }
        //目前设计只支持java、python、c
        String language = executeCodeRequest.getLanguage();
        if("java".equals(language)){
            ExecuteCodeResponse executeCodeResponse = javaNativeCodeSendBox.ExecuteCode(executeCodeRequest);
            return executeCodeResponse;
        }else if("python".equals(language)){
            ExecuteCodeResponse executeCodeResponse = pythonNativeCodeSendBox.ExecuteCode(executeCodeRequest);
            return executeCodeResponse;
        }else{
            ExecuteCodeResponse executeCodeResponse = cNativeCodeSendBox.ExecuteCode(executeCodeRequest);
            return executeCodeResponse;
        }
    }

    @GetMapping("get")
    public String test(){
        return "hello";
    }

}
